import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:C20Driver/config/service_api.dart';
import 'package:C20Driver/model/get_share_info_model.dart';
import '../service/service_method.dart';

///[WeChatScene.SESSION]会话
///[WeChatScene.TIMELINE]朋友圈
///[WeChatScene.FAVORITE]收藏

class Wechat {
  // 微信分享给朋友
  static void weChatShareWebSession(String userId) async {
    await DioUtils().request(
      ReqMethod.POST,
      ServiceApi.getShareInfo,
      params: {'type': '0020'},
      success: (res) async {
        GetShareInfo shareData = GetShareInfo.fromJson(res);
        var model = fluwx.WeChatShareWebPageModel(
          shareData.url + '?userId=$userId',
          title: shareData.title,
          description: shareData.content,
          thumbnail: fluwx.WeChatImage.network(shareData.logo),
          scene: fluwx.WeChatScene.SESSION,
        );
        fluwx.shareToWeChat(model);
      },
    );
  }

  // 微信分享到朋友圈
  static void weChatShareWebTimeline(userId) async {
    await DioUtils().request(
      ReqMethod.POST,
      ServiceApi.getShareInfo,
      params: {'type': '0020'},
      success: (res) async {
        GetShareInfo shareData = GetShareInfo.fromJson(res);
        var model = fluwx.WeChatShareWebPageModel(
          shareData.url + '?userId=$userId',
          title: shareData.title,
          description: shareData.content,
          thumbnail: fluwx.WeChatImage.network(shareData.logo),
          scene: fluwx.WeChatScene.TIMELINE,
        );
        fluwx.shareToWeChat(model);
      },
    );
  }

  // // 文本分享
  static void weChatShareText(String shareTxt) async {
    // var model = fluwx.WeChatShareTextModel(
    //     text: shareTxt,
    //     transaction:
    //         "text${DateTime.now().millisecondsSinceEpoch}", //仅在android上有效，下同。
    //     scene: fluwx.WeChatScene.SESSION);
    // fluwx.shareToWeChat(model);
  }

  // // 视频分享
  // static void weChatShareVideo(
  //     String _videoUrl,
  //     String _title,
  //     String _thumnail,
  //     String _videoLowBandUrl,
  //     scene,
  //     String _description) async {
  //   var model = fluwx.WeChatShareVideoModel(
  //       videoUrl: _videoUrl,
  //       transaction: "video",
  //       videoLowBandUrl: _videoLowBandUrl,
  //       thumbnail: _thumnail,
  //       description: _description,
  //       scene: scene,
  //       title: _title);
  //   fluwx.share(model);
  // }

  // // 微信登录
  // static void weChatLogin() {
  //   fluwx
  //       .sendAuth(scope: "snsapi_userinfo", state: "wechat_sdk_demo_test")
  //       .then((data) {});
  // }

  /// 微信支付
  static Future<bool> weChatPay(
      {@required String appid,
      @required String partnerid,
      @required String prepayid,
      @required String package,
      @required String noncestr,
      @required int timestamp,
      @required String sign}) {
    return fluwx.payWithWeChat(
      appId: appid,
      partnerId: partnerid,
      prepayId: prepayid,
      packageValue: package,
      nonceStr: noncestr,
      timeStamp: timestamp,
      sign: sign,
    );
  }

  // // 打开微信小程序
  // static void weChatWeapp() {
  //   fluwx.launchMiniProgram(
  //     username: "gh_eb87c8d5bf06"
  //   );
  // }

}
